<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>数据库配置 - Powered by {:C('SYSTEM_WEBNAME')}</title>
	<Pintuer />
	<Layer />
	<style>
	.body-box{
		position: absolute;
		top:100px;
		left:300px;
		right:300px;
		bottom:150px;
		background: rgba(255,255,255,0.5);
		box-shadow: 1px 1px 3px;
	}
	.install-box{
		width:100%;
		height:100%;
	}
	.logo{
		background: #394049;
		height:60px;
	}
	.content{
		height:80%;
		overflow:auto;
		border-bottom:#FFF 1px solid;
		margin-bottom:10px;
		padding-top:10px;
		padding-left:10px;
		padding-bottom: 20px;
	}
	.text-block{
		display: block;
	}
	</style>
</head>
<body class="bg-blue">
	<div class="body-box">
		<form id="form-database" class="form-auto">
			<div class="install-box">
				<div class="logo">
					<div class="line">
						<div class="x2">
							<img src="__PUBLIC__/images/logo.png" width="200" height="60">
						</div>
						<div class="x10 padding-big-top">
							<span class="text-white text-big">数据库配置</span>
						</div>
					</div>
				</div>
				<div class="content">
					<div class="line margin-top">
						<div class="x4 text-right padding-right padding-small-top">
							<strong class="text-big">
								数据库设置
							</strong>
						</div>
						<div class="x8 padding-right"></div>
					</div>
					<div class="line margin-top">
						<div class="x4 text-right padding-right padding-small-top">
							数据库地址：
						</div>
						<div class="x8 padding-right">
							<input type="text" name="DB_HOST" size="35" class="input" value="127.0.0.1">
						</div>
					</div>
					<div class="line margin-top">
						<div class="x4 text-right padding-right padding-small-top">
							数据库用户：
						</div>
						<div class="x8 padding-right">
							<input type="text" name="DB_USER" size="35" class="input">
						</div>
					</div>
					<div class="line margin-top">
						<div class="x4 text-right padding-right padding-small-top">
							数据库密码：
						</div>
						<div class="x8 padding-right">
							<input type="password" name="DB_PWD" size="35" class="input">
						</div>
					</div>
					<div class="line margin-top">
						<div class="x4 text-right padding-right padding-small-top">
							数据库名称：
						</div>
						<div class="x8 padding-right">
							<input type="text" name="DB_NAME" size="35" class="input">
						</div>
					</div>
					<div class="line margin-top">
						<div class="x4 text-right padding-right padding-small-top">
							数据库端口：
						</div>
						<div class="x8 padding-right">
							<input type="text" name="DB_PORT" size="35" class="input" value="3306">
						</div>
					</div>
					<div class="line margin-top">
						<div class="x4 text-right padding-right padding-small-top">
							数据表前缀：
						</div>
						<div class="x8 padding-right">
							<input type="text" name="DB_PREFIX" size="35" class="input" value="php_">
						</div>
					</div>
					<div class="line margin-top">
						<div class="x4 text-right padding-right padding-small-top">
							<strong class="text-big">
								站点设置
							</strong>
						</div>
						<div class="x8 padding-right"></div>
					</div>
					<div class="line margin-top">
						<div class="x4 text-right padding-right padding-small-top">
							管理员账号：
						</div>
						<div class="x8 padding-right">
							<input type="text" name="admin_user" size="35" class="input">
						</div>
					</div>
					<div class="line margin-top">
						<div class="x4 text-right padding-right padding-small-top">
							管理员密码：
						</div>
						<div class="x8 padding-right">
							<input type="password" name="admin_pass" size="35" class="input">
						</div>
					</div>
					<div class="line margin-top">
						<div class="x4 text-right padding-right padding-small-top">
							站长邮箱：
						</div>
						<div class="x8 padding-right">
							<input type="text" name="admin_email" size="35" class="input">
						</div>
					</div>
				</div>
				<div class="text-center margin-big-top">
					<button type="button" onclick="window.location.href='{:U('validates')}'" class="button bg-red">
						上一步
					</button>
					<button type="submit" class="button bg-green">
						立即安装
					</button>
				</div>
			</div>
		</form>
	</div>
	<script>
		$(function(){
			$('#form-database').submit(function(e){
				e.preventDefault();
				// 数据验证
				if ($(this).find('input[name=DB_HOST]').val() == '') {
					layer.msg('请输入数据库地址');
					$(this).find('input[name=DB_HOST]').focus();
					return false
				};
				if ($(this).find('input[name=DB_USER]').val() == '') {
					layer.msg('请输入数据库用户');
					$(this).find('input[name=DB_USER]').focus();
					return false
				};
				if ($(this).find('input[name=DB_NAME]').val() == '') {
					layer.msg('请输入数据库名称');
					$(this).find('input[name=DB_NAME]').focus();
					return false
				};
				if ($(this).find('input[name=DB_PORT]').val() == '') {
					layer.msg('请输入数据库端口');
					$(this).find('input[name=DB_PORT]').focus();
					return false
				};
				if ($(this).find('input[name=DB_PREFIX]').val() == '') {
					layer.msg('请输入数据表前缀');
					$(this).find('input[name=DB_PREFIX]').focus();
					return false
				};
				if ($(this).find('input[name=admin_user]').val() == '') {
					layer.msg('请输入管理员账号');
					$(this).find('input[name=admin_user]').focus();
					return false
				};
				if ($(this).find('input[name=admin_pass]').val() == '') {
					layer.msg('请输入管理员密码');
					$(this).find('input[name=admin_pass]').focus();
					return false
				};
				if ($(this).find('input[name=admin_email]').val() == '') {
					layer.msg('请输入管理员邮箱');
					$(this).find('input[name=admin_email]').focus();
					return false
				};
				// 获取表单数据
				var data = $(this).serialize();

				// ajax
				$.ajax({
					url : "{:U(database)}",
					data : data,
					dataType : 'json',
					type : 'post',
					error : function(err){
						alert(JSON.stringify(err));
					},
					success : function(ret){
						if (ret.status == 1) {
							layer.msg(ret.info,{
								icon : 6
							},function(){
								window.location.href=ret.url;
							});
						}else{
							layer.msg(ret.info);
						};
					},
				});
			});
		});
    </script>
</body>
</html>